<template>
  <DataList ref="datalist" :cate="cate" :cols="cols" :name="name" skipExcelNumber="4" :excelHeader="excelHeader"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import { addSjjyqk, deleteSjjyqk, updateSjjyqk, getSjjyqk, bulkAddSjjyqk } from "@/api/上届毕业生就业情况.js";
import {findComponent} from "@/utils/ui";
import {get开设专业} from  "@/api/开设专业"
import linq from "linq"
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A7-6-3上届毕业生就业情况表",
      name: "7.6.3 上届毕业生就业情况",
      excelHeader:{B3:"专业所属系部代码",C3:"专业所属系部名称",D3:"专业代码",E3:"专业名称（全称）",F3:"专业方向代码",G3:"专业方向名称（全称）",
      H3:"毕业生数（人）",I3:"毕业生就业情况",I4:"12月31日就业",I5:"就业数(人)",J5:"就业率（%）",K4:"升迁",K4:"转岗",K5:"转岗数（人）",L5:"转岗率（%）",M3:"毕业生用人单位满意情况",
      M4:"满意或基本满意",M5:"人数（人）",N5:"比例（％）",O4:"一般满意",O5:"人数（人）",P5:"比例（％）",Q4:"不满意",Q5:"人数（人）",R5:"比例（％）"},
      cols: [
        { label: "专业所属系部代码", prop: "BMBH" },
        { label: "专业所属系部名称", prop: "BMMC" },
        { label: "专业代码", prop: "ZYDM" },
        { label: "专业名称(全称)", prop: "ZYMC" },
        { label: "专业方向代码", prop: "ZYFXDM" },
        { label: "专业方向名称(全称)", prop: "ZYFXMC" },
        { label: "毕业生数(人)", prop: "BYSS" },
        { label: "毕业生就业情况" ,data:[
              {label:"12月31日就业",data:[
                {label:"就业数(人)",prop:"JYQK_1231_JYS"},
                {label:"就业率(%)",prop:"JYQK_1231_JYL"}
                ]},
                // {label:"升迁",data:[
                // {label:"升迁数(人)",prop:"JYQK_SQ_SQS"},
                // {label:"升迁率(%)",prop:"JYQK_SQ_SQL"}
                // ]},
                {label:"转岗",data:[
                {label:"转岗数(人)",prop:"JYQK_ZG_ZGS"},
                {label:"转岗率(%)",prop:"JYQK_ZG_ZGL"}
                ]}
        ]},
        { label: "毕业生用人单位满意情况" ,data:[
              {label:"满意或基本满意",data:[
                {label:"人数(人)",prop:"MYQK_MYHJBMY_RS"},
                {label:"比例(%)",prop:"MYQK_MYHJBMY_BL"}
                ]},
                {label:"一般满意",data:[
                {label:"人数(人)",prop:"MYQK_YBMY_RS"},
                {label:"比例(%)",prop:"MYQK_YBMY_BL"}
                ]},
                {label:"不满意",data:[
                {label:"人数(人)",prop:"MYQK_BMY_RS"},
                {label:"比例(%)",prop:"MYQK_BMY_BL"}
                ]}
        ]}
      ]
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
         sums[0]="合计";
         sums[6]="系部数:"+linq.from(list).distinct("$.BMBH").count()
         sums[8]="专业数:"+linq.from(list).distinct("$.ZYDM").count()
         sums[10]="方向数:"+linq.from(list).distinct("$.ZYFXDM").count()
         sums[12]="总人数:"+linq.from(list).sum("$.BYSS")
         sums[13]=""+linq.from(list).sum("$.JYQK_1231_JYS")
         sums[14]=""+((linq.from(list).sum("$.JYQK_1231_JYS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
        //  sums[11]=""+linq.from(list).sum("$.JYQK_SQ_SQS")
        //  sums[12]=""+((linq.from(list).sum("$.JYQK_SQ_SQS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[15]=""+linq.from(list).sum("$.JYQK_ZG_ZGS")
         sums[16]=""+((linq.from(list).sum("$.JYQK_ZG_ZGS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[17]=""+linq.from(list).sum("$.MYQK_MYHJBMY_RS")
         sums[18]=""+((linq.from(list).sum("$.MYQK_MYHJBMY_RS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[19]=""+linq.from(list).sum("$.MYQK_YBMY_RS")
         sums[20]=""+((linq.from(list).sum("$.MYQK_YBMY_RS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[21]=""+linq.from(list).sum("$.MYQK_BMY_RS")
         sums[22]=""+((linq.from(list).sum("$.MYQK_BMY_RS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[23]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
         sums[23]+= ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
         sums[23] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
 
       return sums;
      //
    },
  async  onDlgCreated(model) {
            var dd = findComponent(this,"ZYFXMC");
          var ZYFXMC = linq.from( this.$root.开设专业).distinct("$.ZYFXMC").toArray();
        
          dd.$attrs.items = ZYFXMC.map(item => {
            return { label: item.ZYFXMC, value: item.ZYFXMC};
          });
    },
    onChange(model, field, value) {
      //
    
      //
      
     if (field == "ZYFXMC") {
        
        var temp =  linq.from( this.$root.开设专业).first(item=>item.ZYFXMC==value);
        model.BMBH = temp.BMBH;
        model.BMMC = temp.BMMC;
        model.ZYMC = temp.ZYMC;
        model.ZYDM = temp.ZYDM;
        
        model.ZYFXDM = temp.ZYFXDM;
        
      }
      //
      
      model.JYQK_1231_JYL=((Number(model.JYQK_1231_JYS)/Number(model.BYSS))*100).toFixed(2)+'';
      //model.JYQK_SQ_SQL=((Number(model.JYQK_SQ_SQS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.JYQK_ZG_ZGL=((Number(model.JYQK_ZG_ZGS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.MYQK_MYHJBMY_BL=((Number(model.MYQK_MYHJBMY_RS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.MYQK_YBMY_BL=((Number(model.MYQK_YBMY_RS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.MYQK_BMY_BL=((Number(model.MYQK_BMY_RS)/Number(model.BYSS))*100).toFixed(2)+'';
    },
    calField(list){
      list.forEach(model=>{
        model.JYQK_1231_JYL=((Number(model.JYQK_1231_JYS)/Number(model.BYSS))*100).toFixed(2)+'';
     // model.JYQK_SQ_SQL=((Number(model.JYQK_SQ_SQS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.JYQK_ZG_ZGL=((Number(model.JYQK_ZG_ZGS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.MYQK_MYHJBMY_BL=((Number(model.MYQK_MYHJBMY_RS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.MYQK_YBMY_BL=((Number(model.MYQK_YBMY_RS)/Number(model.BYSS))*100).toFixed(2)+'';
      model.MYQK_BMY_BL=((Number(model.MYQK_BMY_RS)/Number(model.BYSS))*100).toFixed(2)+'';


         model.JYQK_1231_JYL=isNaN(model.JYQK_1231_JYL)?0:model.JYQK_1231_JYL;

         model.JYQK_SQ_SQL=isNaN(model.JYQK_SQ_SQL)?0:model.JYQK_SQ_SQL;

         model.JYQK_ZG_ZGL=isNaN(model.JYQK_ZG_ZGL)?0:model.JYQK_ZG_ZGL;

         model.MYQK_MYHJBMY_BL=isNaN(model.MYQK_MYHJBMY_BL)?0:model.MYQK_MYHJBMY_BL;

         model.MYQK_YBMY_BL=isNaN(model.MYQK_YBMY_BL)?0:model.MYQK_YBMY_BL;

         model.MYQK_BMY_BL=isNaN(model.MYQK_BMY_BL)?0:model.MYQK_BMY_BL;
      })
     },
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
         try{
          var user = getUser();
          var 专业 = await get开设专业(user.XXID,user.CJPC)
                 
          //是否已经存在相同
          
          var err =  linq.from(array).select("$.ZYDM+','+$.ZYFXDM").except(linq.from(专业).select("$.ZYDM+','+$.ZYFXDM").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYFXDM) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"开设专业表不存在对应的专业代码与专业方向代码组合合");
          //把错误的教师姓名替代掉
          err =  linq.from(array).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").except(linq.from(专业).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYMC+','+e.ZYFXDM+','+e.ZYFXMC) !==-1).
          forEach(e=>{
            var d = linq.from(专业).firstOrDefault(item=>item.ZYDM == e.ZYDM && item.ZYFXDM == e.ZYFXDM);
            if(d){
              e.ZYMC = d.ZYMC;
              e.ZYFXMC = d.ZYFXMC;
              e.BMMC = d.BMMC;
              e.BMBH = d.BMBH;
            }
          });
            resolve();
          }catch(e){
            reject(e);
          }
     }) 
    },
    async  bulkAdd(array){
       await  bulkAddSjjyqk({Sjjyqk:array});
    },
    async fetchData() {
      var user =  getUser()
      var datas = await getSjjyqk(user.XXID,user.CJPC);
      console.log(datas)
      return datas;
    },
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
      
          console.log(JSON.stringify(temp));
          
          var model = await addSjjyqk(temp);
          resolve(model);
      })
      
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateSjjyqk(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
         await deleteSjjyqk(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>